package oop.ex2.tokenizer;

import java.util.ArrayList;
import oop.ex2.expression.ExpressionNode;
import oop.ex2.expression.CustomFunctionNode;
import oop.ex2.expression.ExpressionSolver;
import oop.ex2.expression.ExpressionTree;

/**
 * This analyzers searches for a custom function name. It stores a list of variables and
 * an expression tree that it uses to construct a custom function node.
 * @author daniel_i_l
 *
 */
public class CustomFunctionAnalyzer extends FunctionAnalyzer {
    private ExpressionTree _functionCalcultor;
    private ArrayList<String> _argumentNames;
    private ExpressionSolver _expressionSolver;

    /**
     * Construct a custom function analyzer using the function name, a list of argument names,
     * the custom expression tree and an expression solver that the custom function should use
     * to set the argument names.
     * @param functionName The function name.
     * @param argumentNames The argument names.
     * @param functionCalculator The expression tree used to calculate the custom function.
     * @param expressionSolver The expression solver.
     */
	public CustomFunctionAnalyzer(String functionName,
            ArrayList<String> argumentNames, ExpressionTree functionCalculator,
            ExpressionSolver expressionSolver) {

		super(functionName);
        _functionCalcultor = functionCalculator;
        _expressionSolver = expressionSolver;
        _argumentNames = argumentNames;
	}

	@Override
	public ExpressionNode getExpressionNode() {
		return new CustomFunctionNode(_matchedString, _argumentNames, _functionCalcultor,
                _expressionSolver);
	}

}
